<form id="user-form" lay-filter="user-form" class="layui-form model-form">
	<input name="creatorId" type="hidden"/>
	<input name="orgId" type="hidden"/>
	<div class="layui-form-item">
		<label class="layui-form-label">群组名</label>
		<div class="layui-input-block">
			<input name="name" placeholder="请输入群组名" type="text" class="layui-input" maxlength="20" lay-verify="required" required/>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">标签</label>
		<div class="layui-input-block">
			<select name="label" xm-select="label" lay-verify="required">
			</select>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">备注</label>
		<div class="layui-input-block">
			<textarea name='remark' placeholder="请输入备注" class="layui-textarea" lay-verify="required" required></textarea>
		</div>
	</div>
	<div class="layui-form-item model-form-footer">
		<button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
		<button class="layui-btn" lay-filter="user-form-submit" lay-submit>保存</button>
	</div>
</form>

<script>
	layui.use(['layer', 'admin', 'form', 'formSelects', 'config'], function() {
		var layer = layui.layer;
		var admin = layui.admin;
		var form = layui.form;
		var formSelects = layui.formSelects;
		var config = layui.config;
		
		form.render('radio');

		// 获取所有角色
		layer.load(2);
		admin.req('role_list.json', {}, function(data) {
			layer.closeAll('loading');
			if(0 == data.code) {
				// 渲染多选下拉框
				var roleSelectData = new Array();
				for(var i = 0; i < data.data.length; i++) {
					roleSelectData.push({
						name: data.data[i].roleName,
						value: data.data[i].label
					});
				}
				formSelects.data('label', 'local', {
					arr: roleSelectData
				});
			} else {
				layer.msg('获取角色失败', {
					icon: 2
				});
			}
			var user = config.getTempData('crid');
			$('#user-form').attr('method', 'GET');
			console.log(user)
			if(user) {
				form.val('user-form', user);
				$('#user-form').attr('method', 'GET');
			}
		}, 'GET');

		// 表单提交事件
		form.on('submit(user-form-submit)', function(data) {
			console.log(data)
            layer.load(2);
			$.ajax({
				type: "POST",
				url: creatGroupPath,
				data: {
					params: JSON.stringify(data.field)
				},
				dataType: "json",
				xhrFields: {
					withCredentials: true
				},
				success: function(data) {
					layer.closeAll('loading');
					layer.msg(data.msg, {
						icon: 1
					});
					admin.finishPopupCenter();
					$('#user-form').attr('method')
				},
				error: function(result) {
					console.log(result);
				},
			});
			
			//          admin.req('user_state.json', data.field, function (data) {
			//              layer.closeAll('loading');
			//              if (data.code == 200) {
			//                  layer.msg(data.msg, {icon: 1});
			//                  admin.finishPopupCenter();
			//              } else {
			//                  layer.msg(data.msg, {icon: 2});
			//              }
			//          }, $('#user-form').attr('method'));
			          return false;
		});
	});
</script>